import { ChannelListType } from '@/store/reducer/channel';
import { TokenType } from '@/store/reducer/user';

const TOKEN_KEY = 'token-mobile';
const CHANNEL_KEY = 'channelUser-list';
export function getToken(): TokenType {
  return JSON.parse(localStorage.getItem(TOKEN_KEY) || '{}');
}
export function setToken(auth: TokenType): void {
  localStorage.setItem(TOKEN_KEY, JSON.stringify(auth));
}
export function removeToken(): void {
  localStorage.removeItem(TOKEN_KEY);
}
export function hasToken(): boolean {
  return !!getToken().token;
}

//频道列表
export function getChannel(): ChannelListType[] {
  return JSON.parse(localStorage.getItem(CHANNEL_KEY) || '[]');
}
export function setChannel(channel: ChannelListType[]): void {
  localStorage.setItem(CHANNEL_KEY, JSON.stringify(channel));
}
export function removeChannel(): void {
  localStorage.removeItem(CHANNEL_KEY);
}
export function hasChannel(): boolean {
  return !!getChannel().toString();
}
